<?php

namespace App\Console;

use Carbon\Carbon;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param \Illuminate\Console\Scheduling\Schedule $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $carbon = Carbon::now();
        $schedule->command('get:redis_data')->withoutOverlapping()->everyMinute();//每分钟从redis拿阅读数据处理
        $schedule->command('domain:get')->everyMinute();//每分钟抓取域名

        $yesterday = $carbon->subDay()->toDateString();
        $schedule->command('domain:check')->withoutOverlapping()->everyMinute();//每分钟检测域名
        $schedule->command('check_order:stat')->withoutOverlapping()->everyFiveMinutes();//每五分钟统计检测订单数据
        $schedule->command('curve_order:insert')->withoutOverlapping()->everyFiveMinutes();//每五分钟插入曲线订单数据

        $schedule->command('domain:stat')->everyFiveMinutes();//每5分钟统计域名使用次数
        $schedule->command('get:order_read_info')->withoutOverlapping()->everyFiveMinutes();//每5分钟更新订单数据
        $schedule->command('refresh:ad')->everyMinute();//每分钟更新订单广告列表
        $schedule->command('domain:change')->withoutOverlapping()->hourly();//每小时更换域名
        $schedule->command('stat:flow_channel')->everyTenMinutes();//每十分钟更新流量主收益数据
        $schedule->command('check_order:match')->hourly();//每小时为流量渠道匹配检测订单
        $last_hour = Carbon::now()->subHour();
        $schedule->command('stat:flow_channel ' . $last_hour->toDateString() . ' ' . $last_hour->hour)->hourlyAt(10);//每小时的十分补充更新上个小时段的流量主收益数据
        $schedule->command('redis:clear '.$yesterday)->dailyAt('00:05');//每天清除前一天的redis数据

        $schedule->command('get:redis_check_order_data')->withoutOverlapping()->everyMinute();//每分钟从redis拿检测订单数据处理

        $schedule->command('get:redis_data '.$yesterday)->dailyAt('00:01');//凌晨处理前一天数据


    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__ . '/Commands');

        require base_path('routes/console.php');
    }
}
